import SnakeUserData from "../multiPlatform/login/SnakeUserData";
import SaveManager from "../save/SaveManager";
import LogTool from "../tool/LogTool";
import BaseManager, { SystemType } from "./BaseManager";

/**
 *  游戏适配类型
 */
export enum GameRaidoType {
    /**
     * 未知
     */
    UnKnow,
    /**
     * 超长
     */
    RadioLang,
    /**
     * 正常
     */
    RadioNormal,
    /**
     * Andorid 16:10
     */
    RadioNormalPaid,
    /**
     *  Apple 3:2 
     */
    RadioApplePaid,
}

class SnakeGameCenter extends BaseManager {
    public static readonly IsFristOpenAppKey: string = "IsFristOpenApp";

    public static readonly instance = new SnakeGameCenter();
    /**
     * 屏幕比例
     */
    private mWindowScreenScale: number = 1;
    public get WindowScreenScale(): number {
        return this.mWindowScreenScale;
    }

    /**
     * 屏幕比例方案
     */
    private mGameRaidoType: GameRaidoType = GameRaidoType.RadioNormal;
    public get GameRaidoType(): GameRaidoType {
        return this.mGameRaidoType;
    }

    /**
     * 用户信息
     */
    private mSnakeUserData: SnakeUserData = new SnakeUserData();
    public get SnakeUserData(): SnakeUserData {
        return this.mSnakeUserData;
    }

    /**
     * 好友信息
     */
    private mFriendSnakeUserDataArray: Array<SnakeUserData> = [];
    public get FriendSnakeUserDataArray(): Array<SnakeUserData> {
        return this.mFriendSnakeUserDataArray;
    }

    /**
     * 是否第一次打开App
     */
    private mIsFirstOpenApp: boolean = true;
    public get IsFirstOpenApp(): boolean {
        return this.mIsFirstOpenApp;
    }


    constructor() {
        super(SystemType.SnakeGameCenter);
    }

    public init(): boolean {
        this.checkScreen();
        LogTool.Log("SnakeGameCenter Init Succeed");
        return true;
    }
    public start(): void {
        LogTool.Log("SnakeGameCenter Start Succeed");
    }
    public ready(): void {

        this.mIsFirstOpenApp = SaveManager.getBool(SnakeGameCenter.IsFristOpenAppKey, this.mIsFirstOpenApp);
        SaveManager.setBool(SnakeGameCenter.IsFristOpenAppKey, false);

        LogTool.Log("SnakeGameCenter Ready Succeed");
    }
    public close(): void {
        LogTool.Log("SnakeGameCenter Close Succeed");
        SaveManager.setBool(SnakeGameCenter.IsFristOpenAppKey, false);
    }

    public checkScreen(): void {
        let winWidth = Math.max(cc.winSize.width, cc.winSize.height);
        let height = Math.min(cc.winSize.width, cc.winSize.height);
        this.mWindowScreenScale = winWidth / height;

        LogTool.Log("屏幕 winWidth = " + winWidth + "height = " + height);
        LogTool.Log("长宽比 s = " + this.mWindowScreenScale);

        if (this.mWindowScreenScale >= 1.9) {
            LogTool.Log("屏幕 比例超出正规值");
            this.mGameRaidoType = GameRaidoType.RadioLang;
        }
        else if (this.mWindowScreenScale >= 1.7 && this.mWindowScreenScale < 1.9) {
            LogTool.Log("屏幕 正常比例");
            this.mGameRaidoType = GameRaidoType.RadioNormal;
        }
        else if (this.mWindowScreenScale > 1.4 && this.mWindowScreenScale < 1.7) {
            LogTool.Log("屏幕比例接近 16:10 ipaid");
            this.mGameRaidoType = GameRaidoType.RadioNormalPaid;
        }
        else if (this.mWindowScreenScale <= 1.4) {
            LogTool.Log("屏幕 比例接近ipaid");
            this.mGameRaidoType = GameRaidoType.RadioApplePaid;
        }
    }

    /**
     * 清空好友
     */
    public clearFriend(): void {
        this.mFriendSnakeUserDataArray = [];
    }

    /**
     * 添加好友数据
     * @param SnakeUserData 
     */
    public addFriend(SnakeUserData: SnakeUserData): void {
        if (SnakeUserData)
            this.mFriendSnakeUserDataArray.push(SnakeUserData);
    }
}
export default (SnakeGameCenter.instance);